package animator.phantom.gui;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.controller.*;
import animator.phantom.controller.keyaction.*;
import animator.phantom.renderer.*;
import animator.phantom.renderer.param.*;
import animator.phantom.paramedit.*;
import animator.phantom.paramedit.panel.ParamEditPanel;
import animator.phantom.gui.timeline.*;
import animator.phantom.gui.keyframe.*;
import animator.phantom.gui.flow.*;
import animator.phantom.gui.view.*;
import animator.phantom.gui.view.component.*;
import animator.phantom.gui.preview.*;
import animator.phantom.gui.*;
import animator.phantom.project.*;
import java.util.Vector;
import java.awt.geom.Point2D;
import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.metal.*;
import animator.phantom.gui.flow.RenderFlowViewButtons;
import javax.swing.UIManager.*;

public class AnimatorFrame extends JFrame implements ActionListener, ChangeListener
{
	public static final int FLOW_EDITOR_TAB_INDEX = 0;
	public static final int CLIP_EDITOR_TAB_INDEX = 1;
	public static final int KEYFRAME_EDITOR_TAB_INDEX = 2;

	private JViewport flowViewPort;
	private JPanel contentPane = null;
	private JTabbedPane editorsPane = null;

	public JToggleButton viewEditorButton;
	public JToggleButton previewButton;

	private FlowEditPanel renderFlowPanel;
	private PreViewPanel previewPanel;

	private JPanel clipKFPanel;
	private	JPanel timelinePanel;
	private JPanel keyEditorPanel;
	private JPanel screenViewsPanel;
	private	JPanel flowPanel;
	private JPanel viewPanel;
	private JPanel previewHolder;
	private JPanel bigEditSwitchButtons;

	private boolean initializing = false;

	public AnimatorFrame()
	{
		super();
		setVisible( false );//set visible when properly initialized.
	}

	//--- Intis editor. Called when program started or
	//--- project loaded.
	public void initializeEditor()
	{
		setTitle(  ProjectController.getName() + " - Phantom2D" );
 
		try
		{
			setIconImage( GUIResources.getResourceBufferedImage( GUIResources.phantomIcon ) );
		}
		catch( Exception e ){}

		System.out.println( "asdasd" );
		createGui();
		requestFocus();
	}

	//--- Create gui. All components are recreated. 
	private void createGui()
	{
		AppUtils.printTitle( "INIT GUI" );

		initializing = true;

		//--- CREATE GUI COMPONENTS, CREATE GUI COMPONENTS, CREATE GUI COMPONENTS
		//--- Render flow editor
		//--- Panel used to select file sources for inclusion in render flow.
		BinsAreaPanel binAreaPanel = new BinsAreaPanel( ProjectController.getBins(), this );

		int flowW = EditorPersistance.getIntPref( EditorPersistance.FLOW_WIDTH );
		int flowH = EditorPersistance.getIntPref( EditorPersistance.FLOW_HEIGHT );

 		renderFlowPanel = new FlowEditPanel( flowW, flowH );
		Vector<FlowBox> boxes = ProjectController.getBoxes();
		renderFlowPanel.loadBoxes( boxes );

		TCPanel flowTcPanel = new TCPanel();
		NormalizedTimelineDisplay normTline = new NormalizedTimelineDisplay();
		RenderFlowViewButtons renderFlowButtons = new RenderFlowViewButtons( this, flowTcPanel, normTline );

		JScrollPane flowScrollPane = new JScrollPane( renderFlowPanel,
			 ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
		flowScrollPane.getVerticalScrollBar().setUnitIncrement(16);
		JPanel flowHolder = new JPanel();
		flowHolder.add( flowScrollPane );
		//--- Add listener so image can be updated when scrolled.
		flowViewPort = flowScrollPane.getViewport();

		ViewEditor viewEdit = new ViewEditor( ProjectController.getScreenSize() );

		screenViewsPanel = new JPanel();
		screenViewsPanel.setLayout( new BigEditorsLayout() );

		ViewControlButtons viewControlButtons = new ViewControlButtons(screenViewsPanel);

		JScrollPane viewScrollPane = new JScrollPane( viewEdit,
			 ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
			 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );

		ParamEditFrame editFrame = new ParamEditFrame();

		TimeLineToolButtons timeLineToolButtons = new TimeLineToolButtons();

		TCPanel tcPanel = new TCPanel();

		TimeLineMarkButtons timeLineMarkButtons = new TimeLineMarkButtons();

		TimeLineEditButtons timeLineEditButtons = new TimeLineEditButtons();

		TimeLineNaviButtons timeLineNaviButtons = new TimeLineNaviButtons();

		TimeLineRangeButtons timeLineRangeButtons = new TimeLineRangeButtons();

		TimeLineSliders timeSliders = new TimeLineSliders();

		TimeLineDisplayPanel timeLineDisplay = new TimeLineDisplayPanel();

		TimeLineIOPColumnPanel iopColumn = new TimeLineIOPColumnPanel();

		TimeLineEditorPanel timelineEditor = new TimeLineEditorPanel();

		KFToolButtons kfButtons = new KFToolButtons();

		TCPanel KFtcPanel = new TCPanel();

		TimeLineDisplayPanel KFtimeLineDisplay = new TimeLineDisplayPanel();

		KFColumnPanel kfColumnPanel = new KFColumnPanel();

		KeyFrameEditorPanel kfEditPanel = new KeyFrameEditorPanel();

		TimeLineSliders KFtimeSliders = new TimeLineSliders();


		//--- BUILD GUI, BUILD GUI, BUILD GUI, BUILD GUI, BUILD GUI, BUILD GUI, BUILD GUI
		//----------------------------------------------------------- SCREEN VIEWS
		//--- Put menu in frame
		AnimatorMenu menuBar = new AnimatorMenu();
		setJMenuBar( menuBar );

		//--- View switch buttons.
		viewEditorButton = PHButtonFactory.getToggleButton("ViewEditor", 90 );
		previewButton = PHButtonFactory.getToggleButton("Preview", 90 );
		viewEditorButton.setToolTipText( "Key shortcut F2" );
		previewButton.setToolTipText( "Key shortcut F3" );
		ButtonGroup beGroup = new ButtonGroup();
		beGroup.add( viewEditorButton );
		beGroup.add( previewButton );
		beGroup.setSelected( viewEditorButton.getModel(), true );
		viewEditorButton.addActionListener( this );
		previewButton.addActionListener( this );
		viewEditorButton.setFont( GUIResources.BIG_BUTTONS_FONT );
		previewButton.setFont( GUIResources.BIG_BUTTONS_FONT );
		bigEditSwitchButtons = new JPanel();
		bigEditSwitchButtons.setLayout(new BoxLayout( bigEditSwitchButtons, BoxLayout.X_AXIS));
		bigEditSwitchButtons.add( viewEditorButton );
		bigEditSwitchButtons.add( previewButton );

		//--- Preview
		previewPanel = new PreViewPanel();
		JScrollPane previewScrollPane = new JScrollPane( previewPanel,
			 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
			 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
		previewHolder = new JPanel();
		previewHolder.add( previewScrollPane );
		PreViewControlPanel previewControl = new PreViewControlPanel( previewPanel );

		//--- View editorAnd preview
		viewPanel = new JPanel();
		viewPanel.add( viewScrollPane );

		//------------------------------------------------------------- TAB EDITORS
		//--- Flow editor
		flowPanel = new JPanel();
		flowPanel.setLayout( new FlowEditorLayout() );
		flowPanel.add( flowScrollPane );
		flowPanel.add( renderFlowButtons );
		flowPanel.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ));

		//--- Panels for ClipEditor
		//--- Strip with buttons.
		JPanel buttonsStrip = new JPanel();
		JPanel rightStrip = new JPanel();
		rightStrip.setLayout(new BoxLayout( rightStrip, BoxLayout.X_AXIS));
		rightStrip.add( tcPanel );
		//rightStrip.add( Box.createRigidArea(new Dimension( 5, 0 ) ) );
		rightStrip.add( timeLineNaviButtons );
		rightStrip.add( Box.createRigidArea(new Dimension( 3, 0 ) ) );
		rightStrip.add( timeLineMarkButtons );
		rightStrip.add( Box.createRigidArea(new Dimension( 3, 0 ) ) );
		rightStrip.add( timeLineEditButtons );
		rightStrip.add( Box.createHorizontalGlue() );
		rightStrip.setBorder( null );
		buttonsStrip.setLayout( 
			new TimeLineRowLayout( timeLineToolButtons, rightStrip ) );
		buttonsStrip.add( timeLineToolButtons );
		buttonsStrip.add( rightStrip );
		buttonsStrip.setBorder( null );

		//--- Strip with timeline view
		JPanel timeDummyPanelTop = new JPanel();
		JPanel scaleStrip = new JPanel();
		scaleStrip.setLayout( new TimeLineRowLayout( timeDummyPanelTop, timeLineDisplay ) );
		scaleStrip.add( timeDummyPanelTop );
		scaleStrip.add( timeLineDisplay );

		//--- Strip with timeline editor.
		JPanel timeLineEditorStrip = new JPanel();
		timeLineEditorStrip.setLayout( new TimeLineRowLayout( iopColumn, timelineEditor ) );
		timeLineEditorStrip.add( iopColumn );
		timeLineEditorStrip.add( timelineEditor );

		JScrollPane timeEditorScrollPane = new JScrollPane( timeLineEditorStrip,
			 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
			 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );

		//--- Strip with timeline sliders 
		JPanel vSliderPanel = new JPanel();
		vSliderPanel.setLayout( new BoxLayout( vSliderPanel, BoxLayout.X_AXIS));
		JLabel verticalPosL = new JLabel( GUIResources.getIcon( GUIResources.verticalPos ) );
		vSliderPanel.add( verticalPosL );
		JSlider clipVSlider = getVertPosSlider();
		vSliderPanel.add( clipVSlider );
		vSliderPanel.add( Box.createHorizontalGlue() );

		JPanel lowStrip = new JPanel();
		lowStrip.setLayout( new TimeLineRowLayout( vSliderPanel, timeSliders ) );
		lowStrip.add( vSliderPanel );
		lowStrip.add( timeSliders );

		//--- Put timeline editor panel together
		timelinePanel = new JPanel();
		timelinePanel.removeAll();
		timelinePanel.setLayout( new TimeLineEditorLayout( Application.SMALL_WINDOW_WIDTH ) );
		timelinePanel.add( buttonsStrip );
		timelinePanel.add( scaleStrip );
		timelinePanel.add( timeEditorScrollPane );
		timelinePanel.add( lowStrip );

		//--- Panels keyframe editor
		//--- Strip with buttons.
		JPanel kfNamePanel = new JPanel();
		kfNamePanel.setLayout(new BoxLayout( kfNamePanel, BoxLayout.X_AXIS));

		JPanel innerPanel = new JPanel();
		JPanel namePanel = new JPanel();
		innerPanel.setLayout(new BoxLayout( innerPanel, BoxLayout.Y_AXIS));
		innerPanel.add( Box.createRigidArea( new Dimension( 0, 5 ) ) );
		innerPanel.add( namePanel );
		innerPanel.add( Box.createRigidArea( new Dimension( 0, 5 ) ) );

		JLabel nameLabel = new JLabel();
		nameLabel.setForeground( Color.black );
		namePanel.add( nameLabel );
		namePanel.setBackground( GUIColors.selectedColor );
		namePanel.setOpaque( true );

		kfNamePanel.add( innerPanel );
		kfNamePanel.add( Box.createRigidArea( new Dimension( 5, 0 ) ) );

		JPanel keyButtonsStrip = new JPanel();
		JPanel KFrightStrip = new JPanel();
		KFrightStrip.setLayout(new BoxLayout( KFrightStrip, BoxLayout.X_AXIS));
		KFrightStrip.add( KFtcPanel );
		//KFrightStrip.add( Box.createRigidArea(new Dimension( 1, 0 ) ) );
		KFrightStrip.add( kfButtons );
		KFrightStrip.add( Box.createHorizontalGlue() );
		KFrightStrip.setBorder( null );
		keyButtonsStrip.setLayout( 
			new TimeLineRowLayout( kfNamePanel, KFrightStrip ) );
		keyButtonsStrip.add( kfNamePanel );
		keyButtonsStrip.add( KFrightStrip );

		//--- Strip with timeline view
		JPanel keyEditorScaleStrip = new JPanel();
 		JPanel iopLabel = new JPanel();//mitäs tänne pannaan?
		keyEditorScaleStrip.setLayout( new TimeLineRowLayout( iopLabel, KFtimeLineDisplay ) );
		keyEditorScaleStrip.add( iopLabel );
		keyEditorScaleStrip.add( KFtimeLineDisplay );

		//--- Strip with keyframe editor.
		JPanel keyFrameEditorStrip = new JPanel();
		keyFrameEditorStrip.setLayout( new TimeLineRowLayout( kfColumnPanel, kfEditPanel ) );
		keyFrameEditorStrip.add( kfColumnPanel );
		keyFrameEditorStrip.add( kfEditPanel );

		//--- Used for nice frame
		JScrollPane keyEditorScrollPane = new JScrollPane( keyFrameEditorStrip,
			 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
			 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );

		//--- Strip with timeline sliders
		JPanel keyFrameLowStrip = new JPanel();
		JPanel kfVSliderPanel = new JPanel();
		kfVSliderPanel.setLayout( new BoxLayout( kfVSliderPanel, BoxLayout.X_AXIS));
		JLabel verticalPos2 = new JLabel( GUIResources.getIcon( GUIResources.verticalPos ) );
		kfVSliderPanel.add( verticalPos2 );
		JSlider kfVSlider = getVertPosSlider();

		kfVSliderPanel.add( kfVSlider );
		kfVSliderPanel.add( Box.createHorizontalGlue() );
		keyFrameLowStrip.setLayout( new TimeLineRowLayout( kfVSliderPanel, KFtimeSliders ) );
		keyFrameLowStrip.add( kfVSliderPanel );
		keyFrameLowStrip.add( KFtimeSliders );

		//--- Put keyframe editor panel together
		keyEditorPanel = new JPanel();
		keyEditorPanel.setLayout( new TimeLineEditorLayout( Application.SMALL_WINDOW_WIDTH ) );
		keyEditorPanel.add( keyButtonsStrip );
		keyEditorPanel.add( keyEditorScaleStrip );
		keyEditorPanel.add( keyEditorScrollPane );
		keyEditorPanel.add( keyFrameLowStrip );

		//--- Put edits edit tab panel
		editorsPane = new JTabbedPane();
		editorsPane.add( flowPanel, "FlowEditor" );
		editorsPane.add( timelinePanel, "ClipEditor" );
		editorsPane.add( keyEditorPanel, "KeyFrameEditor" );
		editorsPane.setBorder( BorderFactory.createEmptyBorder(  AnimFrameGUIParams.TAB_PANEL_BORDER_WIDTH,
									AnimFrameGUIParams.TAB_PANEL_BORDER_WIDTH,
									AnimFrameGUIParams.TAB_PANEL_BORDER_WIDTH,
									AnimFrameGUIParams.TAB_PANEL_BORDER_WIDTH ));
		editorsPane.setFont( GUIResources.TABBED_PANE_FONT );

		//------------------------------------------------------------------- PUT WHOLE GUI TOGETHER
		contentPane = new JPanel();
		AnimatorFrameLayout frameLayout = new AnimatorFrameLayout( 	screenViewsPanel,
										editorsPane );
		contentPane.setLayout( frameLayout );
		contentPane.add( screenViewsPanel );
		contentPane.add( editorsPane );

		JPanel realContentPanel = new JPanel();
		ContentPaneLayout rclayout = new ContentPaneLayout();
		realContentPanel.setLayout( rclayout );
		realContentPanel.add( binAreaPanel );
		realContentPanel.add( editFrame );
		realContentPanel.add( contentPane );

		//--- Create global keyactions.
		KeyUtils.clearGlobalActions();
		KeyUtils.setGlobalAction( new CTRLPressedAction(), "ctrl pressed CONTROL" );
		KeyUtils.setGlobalAction( new CTRLReleasedAction(), "released CONTROL" );
		KeyUtils.setGlobalAction( new DisplayFlowEditorAction(), EditorPersistance.getStringPref( EditorPersistance.DISP_FLOW_KEY_SC ));
		KeyUtils.setGlobalAction( new DisplayClipEditorAction(),  EditorPersistance.getStringPref( EditorPersistance.DISP_CLIP_KEY_SC ) );
		KeyUtils.setGlobalAction( new DisplayKFEditorAction(),  EditorPersistance.getStringPref( EditorPersistance.DISP_KF_KEY_SC ) );
		KeyUtils.setGlobalAction( new RenderPreviewAction(), EditorPersistance.getStringPref( EditorPersistance.RENDER_PRE_KEY_SC ));
		KeyUtils.setGlobalAction( new RenderPreviewFrameAction(), EditorPersistance.getStringPref( EditorPersistance.RENDER_PRE_FRAME_KEY_SC ));
		KeyUtils.setGlobalAction( new FlowArrangeAction(), EditorPersistance.getStringPref( EditorPersistance.FLOW_ARRANGE_KEY_SC ) );
		KeyUtils.setGlobalAction( new FlowConnectAction(), EditorPersistance.getStringPref( EditorPersistance.FLOW_CONNECT_KEY_SC ) );
		KeyUtils.setGlobalAction( new FlowDisconnectAction(), EditorPersistance.getStringPref( EditorPersistance.FLOW_DISCONNECT_KEY_SC ) );
		KeyUtils.setGlobalAction( new TimelineZoomInAction(), EditorPersistance.getStringPref( EditorPersistance.TLINE_ZOOM_IN_KEY_SC ) );
		KeyUtils.setGlobalAction( new TimelineZoomOutAction(), EditorPersistance.getStringPref( EditorPersistance.TLINE_ZOOM_OUT_KEY_SC ) );
		KeyUtils.setGlobalAction( new TimelinePrevAction(), EditorPersistance.getStringPref( EditorPersistance.TLINE_PREV_KEY_SC ) );
		KeyUtils.setGlobalAction( new TimelineNextAction(), EditorPersistance.getStringPref( EditorPersistance.TLINE_NEXT_KEY_SC ) );
		KeyUtils.setGlobalAction( new NextLayerAction(), EditorPersistance.getStringPref( EditorPersistance.NEXT_LAYER_KEY_SC ));
		KeyUtils.setGlobalAction( new SwitchBigEditorAction(), EditorPersistance.getStringPref( EditorPersistance.SWITCH_BIG_EDITOR_KEY_SC ));

		//--- Create ancestor focus actions
		KeyUtils.setAncestorFocusAction( keyEditorPanel, new CopyAction(), "control C" );
		KeyUtils.setAncestorFocusAction( keyEditorPanel, new PasteAction(), "control V" );
		KeyUtils.setAncestorFocusAction( keyEditorPanel, new DeleteAction(), "DELETE" );

		KeyUtils.setAncestorFocusAction( binAreaPanel, new DeleteAction(), "DELETE" );
		KeyUtils.setAncestorFocusAction( binAreaPanel, new CopyAction(), "control C" );
		KeyUtils.setAncestorFocusAction( binAreaPanel, new PasteAction(), "control V" );
		KeyUtils.setAncestorFocusAction( binAreaPanel, new SelectAllAction(), "control A" );
		KeyUtils.setAncestorFocusAction( binAreaPanel, new DeSelectAllAction(), "control shift A" );

		//--- Connect GUI components to be accessed elsewhere.
		GUIComponents.animatorFrame = this;
		GUIComponents.animatorMenu = menuBar;
		GUIComponents.renderFlowPanel = renderFlowPanel;//this has to be present when loading boxes.
		GUIComponents.timeLineIOPColumnPanel = iopColumn;
		GUIComponents.timeLineEditorPanel = timelineEditor;
		GUIComponents.timeLineScaleDisplays.add( timeLineDisplay );
		GUIComponents.timeLineScaleDisplays.add( KFtimeLineDisplay );
		GUIComponents.renderFlowButtons = renderFlowButtons;
		GUIComponents.tcPanels.add( tcPanel );
		GUIComponents.tcPanels.add( KFtcPanel );
		GUIComponents.tcPanels.add( flowTcPanel );
		GUIComponents.sliders.add( timeSliders );
		GUIComponents.sliders.add( KFtimeSliders );
		ParamEditController.paramEditFrame = editFrame;
		GUIComponents.viewEditor = viewEdit;
		GUIComponents.kfColumnPanel = kfColumnPanel;
		GUIComponents.keyFrameEditPanel = kfEditPanel;
		GUIComponents.kfNamePanel = namePanel;
		GUIComponents.keyEditorContainerPanel = keyEditorPanel;
		GUIComponents.projectPanel = binAreaPanel;//we have 2 references to this and this is not fixed
		GUIComponents.previewPanel = previewPanel;
		GUIComponents.previewControls = previewControl;
		GUIComponents.viewControlButtons = viewControlButtons;
		GUIComponents.viewScrollPane = viewScrollPane;
		GUIComponents.kfControl = kfButtons;
		GUIComponents.binsPanel = binAreaPanel;//we have 2 references to this and this is not fixed
		GUIComponents.kfVertSlider = kfVSlider;
		GUIComponents.clipVertSlider = clipVSlider;
		GUIComponents.normTlineDisp = normTline;

		//--- These need a shake.
		TimeLineController.initClipEditorGUI();

		//--- View editor is first visible
		displayViewEditor();

		//--- Remove all components
		getContentPane().removeAll();

		//--- Put content pane in frame.
		add( realContentPanel );

		setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
		setExtendedState( getExtendedState()|JFrame.MAXIMIZED_BOTH );

		AppUtils.printTitle( "INIT GUI DONE!" );
		initializing = false;

		MinimizeSetTimer minimSet = new MinimizeSetTimer( this );
		minimSet.start();
	}

	//----------------------------------------------- Editor change buttons.
	public void actionPerformed( ActionEvent e )
	{
		if( e.getSource() == viewEditorButton )
		{
			displayViewEditor();
		}
		if( e.getSource() == previewButton )
		{
			 displayPreviewPanel();
		}
	}
	public void switchBigEditor()
	{
		if( screenViewsPanel.getComponent( 0 ) == viewPanel )
			displayPreviewPanel();
		else
			displayViewEditor();
	}
	public void displayViewEditor()
	{
		viewEditorButton.setSelected( true );
		previewButton.setSelected( false );
		screenViewsPanel.removeAll();
		screenViewsPanel.add( viewPanel );
		screenViewsPanel.add( bigEditSwitchButtons );
		screenViewsPanel.add( GUIComponents.viewControlButtons );
		PreviewController.stopPlaybackRequest();
		if( !initializing ) screenViewsPanel.validate();//layer edit buttons may have changed
		if( !initializing ) repaint();
	}	
	public void displayPreviewPanel()
	{
		viewEditorButton.setSelected( false );
		previewButton.setSelected( true );
		screenViewsPanel.removeAll();
		screenViewsPanel.add( previewHolder );
		screenViewsPanel.add( bigEditSwitchButtons );
		screenViewsPanel.add( GUIComponents.previewControls );
		if( !initializing ) screenViewsPanel.validate();
		if( !initializing ) repaint();
	}

	public void setEditorTabSelected( int index )
	{
		PreviewController.stopPlaybackRequest();
		editorsPane.setSelectedIndex( index );
	}

	public int getSelectedEditorTab()
	{
		return editorsPane.getSelectedIndex();
	}

	//--- Helper method
	private JSlider getVertPosSlider()
	{
		JSlider positionSlider = new JSlider( JSlider.HORIZONTAL, 0, 100, 50 );
		positionSlider.addChangeListener( this );
		positionSlider.setPaintTicks( false );
		positionSlider.setPaintLabels(false);
		positionSlider.setPreferredSize( 
			new Dimension( AnimFrameGUIParams.VERTICAL_POS_SLIDER_WIDTH, AnimFrameGUIParams.TE_BOTTOM_STRIP_HEIGHT ) );
		positionSlider.setMaximumSize( 
			new Dimension( AnimFrameGUIParams.VERTICAL_POS_SLIDER_WIDTH, AnimFrameGUIParams.TE_BOTTOM_STRIP_HEIGHT ) );
		return positionSlider;
	}
	//--- Listen to the sliders and forward values.
	public void stateChanged(ChangeEvent e) 
	{
		JSlider source = (JSlider)e.getSource();
		if( e.getSource() == GUIComponents.kfVertSlider )
			GUIComponents.keyFrameEditPanel.setVerticalPos( GUIComponents.kfVertSlider.getValue() );
		if( e.getSource() == GUIComponents.clipVertSlider )
			GUIComponents.timeLineEditorPanel.setVerticalPos( GUIComponents.clipVertSlider.getValue() );
	}
	//------------------------------------------------ render flow view scroll stuff for box placement
	//--- Return x,y of left up corner postion of viewport in RenderFlowViewPanel
	public Point getScrollPos(){ return flowViewPort.getViewPosition(); }
	//--- Return middlepoint for current viewport size.
	public Point getViewPortMiddlePoint()
	{
		 return new Point( flowViewPort.getExtentSize().width / 2,
					flowViewPort.getExtentSize().height / 2 );
	}
	//--- Returns view port size.
	public Dimension getViewPortSize(){ return flowViewPort.getExtentSize(); }

	//--- Used to avoid opening flicker.
	public class MinimizeSetTimer extends Timer
	{
		private SetMinimizeEvent setEvent;
		private JFrame animFrame;

		public MinimizeSetTimer( JFrame frame )
		{
			animFrame = frame;
		}

		public void start()
		{
			setEvent = new SetMinimizeEvent();
			schedule( setEvent, (long) 3000 );
		}

		class SetMinimizeEvent extends TimerTask
		{
			public void run()
			{
				animFrame.setMinimumSize( new Dimension( 1150, 700 ));
			}
		}
	}

}//end class
